package com.kotlin.customview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * author : zhouyouqiang
 * e-mail : 1638473898@qq.com
 * date   : 2022/3/22 11:48
 * desc   :
 * version: 1.0
 */
public class CustomLinearGradient extends View {
    Paint paint=new Paint();
    public CustomLinearGradient(Context context) {
        super(context);
    }

    public CustomLinearGradient(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomLinearGradient(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //LinearGradient 线性渐变
//        Shader shader = new LinearGradient(100, 100, 500, 500, Color.parseColor("#E91E63"),
//                Color.parseColor("#2196F3"), Shader.TileMode.MIRROR);
//        paint.setShader(shader);
//        paint.setAntiAlias(true);
//        canvas.drawCircle(300, 300, 200, paint);

        //RadialGradient 辐射渐变
//        Shader shader = new RadialGradient(300, 300, 200, Color.parseColor("#E91E63"),
//                Color.parseColor("#2196F3"), Shader.TileMode.CLAMP);
//        paint.setShader(shader);
//        canvas.drawCircle(300, 300, 200, paint);

        //SweepGradient 扫描渐变
//        Shader shader = new SweepGradient(300, 300, Color.parseColor("#E91E63"),
//                Color.parseColor("#2196F3"));
//        paint.setShader(shader);
//        canvas.drawCircle(300, 300, 200, paint);

        //BitmapShader
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.girl);
        Shader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        paint.setShader(shader);
        canvas.drawCircle(300, 300, 200, paint);

    }
}
